package com.bt.lms.ui.page.teaching.supervise;

import com.bt.lms.ui.action.teaching.supervise.LookTeachingArrangeDetailLabAction;
import com.bt.lms.ui.action.teaching.supervise.LookTeachingHistoryBtnAction;
import com.bt.lms.ui.action.teaching.supervise.ProcessTeachingArrangeBtnAction;
import com.bt.lms.ui.vo.teachingSupervise.TeachingSuperviseFinishInfo;
import com.bt.lms.ui.vo.teachingSupervise.TeachingSuperviseProcessInfo;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;

import java.util.ArrayList;
import java.util.List;

/**
 * 完成的教学安排
 */
public class FinishTeachingArrange extends VBox {
    /**
     * 已完成的教学安排界面长
     */
    private double preWidth = 1280;
    /**
     * 已完成的教学安排界面高
     */
    private double preHeight = 800;

    /**
     *列名默认长度
     */
    private double columnPreWidth = 100;

    public FinishTeachingArrange(){

        this.setPrefSize(preWidth,preHeight);
        this.setPadding(new Insets(5));
        this.setSpacing(20);

        //顶部横向盒子
        HBox topHBox = new HBox();
        initTopHBox(topHBox);
        //按钮横向盒子
        HBox buttonHBox = new HBox();
        initButtonHBox(buttonHBox);
        //条件搜索区域横向盒子
        HBox searchHBox = new HBox();
        initSearchHBox(searchHBox);
        //表格盒子
        VBox tableVBox = new VBox();
        initTableVBox(tableVBox);
        //页码横向盒子
        HBox pageNumHBox = new HBox();
        initPageNumHBox(pageNumHBox);


        this.getChildren().addAll(topHBox,buttonHBox,searchHBox,tableVBox,pageNumHBox);
    }

    /**
     * 页码横向盒子
     * @param pageNumHBox
     */
    private void initPageNumHBox(HBox pageNumHBox) {
        pageNumHBox.setSpacing(20);
        pageNumHBox.setPadding(new Insets(10));
        pageNumHBox.setAlignment(Pos.CENTER_RIGHT);
        //首页标签
        Label homeLab = new Label("<<首页");
        homeLab.setTextFill(Color.rgb(108,221,83));
        homeLab.setFont(new Font(20));
        //上一页标签
        Label previousPageLab = new Label("<<上一页");
        previousPageLab.setTextFill(Color.rgb(108,221,83));
        previousPageLab.setFont(new Font(20));
        //第一页按钮
        Button onePageBtn = new Button("1");
        onePageBtn.setPrefWidth(27);
        onePageBtn.setPrefHeight(30);
        //第二页按钮
        Button twoPageBtn = new Button("2");
        twoPageBtn.setPrefWidth(27);
        twoPageBtn.setPrefHeight(30);
        //第三页按钮
        Button threePageBtn = new Button("3");
        threePageBtn.setPrefWidth(27);
        threePageBtn.setPrefHeight(30);
        //第四页按钮
        Button fourPageBtn = new Button("4");
        fourPageBtn.setPrefWidth(27);
        fourPageBtn.setPrefHeight(30);
        //下一页标签
        Label nextPageLab = new Label("下一页>>");
        nextPageLab.setFont(new Font(20));
        nextPageLab.setTextFill(Color.rgb(108,221,83));
        //尾页标签
        Label endPageLab = new Label("尾页>>");
        endPageLab.setFont(new Font(20));
        endPageLab.setTextFill(Color.rgb(108,221,83));
        //总记录数条
        Label totalPageLab = new Label("总页数100条");
        totalPageLab.setFont(new Font(20));
        totalPageLab.setTextFill(Color.rgb(255,65,55));
        //条数文本框
        TextField countTF = new TextField();
        countTF.setPrefWidth(100);
        // /10标签
        Label tenLab = new Label("/10");
        tenLab.setFont(new Font(20));
        //GO按钮
        Button goBtn = new Button("GO");


        ObservableList<Node> children = pageNumHBox.getChildren();
        children.addAll(homeLab,previousPageLab,onePageBtn,twoPageBtn,threePageBtn,fourPageBtn,nextPageLab,endPageLab,totalPageLab,countTF,tenLab,goBtn);
    }

    /**
     * 表格盒子
     * @param tableVBox
     */
    private void initTableVBox(VBox tableVBox) {
        //表格
        TableView tableView = new TableView<>();
        TableColumn serialNumColumn = new TableColumn<>("序号");
        serialNumColumn.setPrefWidth(columnPreWidth);
        TableColumn courseNameColumn = new TableColumn<>("课程名称");
        courseNameColumn.setPrefWidth(columnPreWidth);
        TableColumn courseCharacterColumn = new TableColumn<>("课程性质");
        courseCharacterColumn.setPrefWidth(columnPreWidth);

        TableColumn coursePropColumn = new TableColumn<>("课程属性");
        coursePropColumn.setPrefWidth(columnPreWidth);
        TableColumn courseTeacherColumn = new TableColumn<>("授课教师");
        courseTeacherColumn.setPrefWidth(columnPreWidth);
        TableColumn startCourseTimeColumn = new TableColumn<>("开课时间");
        startCourseTimeColumn.setPrefWidth(columnPreWidth);
        TableColumn finishCourseTimeColumn = new TableColumn<>("结课时间");
        finishCourseTimeColumn.setPrefWidth(columnPreWidth);
        TableColumn operationColumn = new TableColumn<>("操作");
        operationColumn.setPrefWidth(columnPreWidth+columnPreWidth);

        //课程名称盒子
        HBox courseNameHBox = new HBox();
        //课程名标签
        Label educationLab = new Label("教育心理学");
        educationLab.setTextFill(Color.rgb(61,140,205));
        courseNameHBox.getChildren().add(educationLab);

        LookTeachingArrangeDetailLabAction lookTeachingArrangeDetailLabAction = new LookTeachingArrangeDetailLabAction();
        educationLab.setOnMouseClicked(lookTeachingArrangeDetailLabAction);

        //数学盒子
        HBox matchHBox = new HBox();
        //数学标签
        Label matchLab = new Label("数学");
        matchLab.setTextFill(Color.rgb(61,140,205));
        matchHBox.getChildren().add(matchLab);

        //英语盒子
        HBox EnglishHBox = new HBox();
        //英语标签
        Label EnglishLab = new Label("英语");
        EnglishLab.setTextFill(Color.rgb(61,140,205));
        EnglishHBox.getChildren().add(EnglishLab);

        //操作列盒子1
        HBox hBox1 = new HBox();
        //查看教学监管历史数据按钮
        Button teachingHistoryBtn1 = new Button("查看教学监管历史数据");
        hBox1.getChildren().add(teachingHistoryBtn1);
        //查看教学监管历史按钮事件
        LookTeachingHistoryBtnAction lookTeachingHistoryBtnAction = new LookTeachingHistoryBtnAction();
        teachingHistoryBtn1.setOnAction(lookTeachingHistoryBtnAction);
        //操作列盒子2
        HBox hBox2 = new HBox();
        //查看教学监管历史数据按钮
        Button teachingHistoryBtn2 = new Button("查看教学监管历史数据");
        hBox2.getChildren().add(teachingHistoryBtn2);
        //操作列盒子3
        HBox hBox3 = new HBox();
        //查看教学监管历史数据按钮
        Button teachingHistoryBtn3 = new Button("查看教学监管历史数据");
        hBox3.getChildren().add(teachingHistoryBtn3);


        //模拟表中数据
        TeachingSuperviseFinishInfo teachingSuperviseFinishInfo1 = new TeachingSuperviseFinishInfo("1",courseNameHBox,"学位专业课","必修","张老师","2009-09-08","2013-01-10",hBox1);
        TeachingSuperviseFinishInfo teachingSuperviseFinishInfo2 = new TeachingSuperviseFinishInfo("2",matchHBox,"基础课","必修","张老师","2009-09-08","2013-01-10",hBox2);
        TeachingSuperviseFinishInfo teachingSuperviseFinishInfo3 = new TeachingSuperviseFinishInfo("3",EnglishHBox,"体育","选修","张老师","2009-09-08","2013-01-10",hBox3);
        //数据集合
        List<TeachingSuperviseFinishInfo>teachingSuperviseFinishInfoList = new ArrayList<>();
        teachingSuperviseFinishInfoList.add(teachingSuperviseFinishInfo1);
        teachingSuperviseFinishInfoList.add(teachingSuperviseFinishInfo2);
        teachingSuperviseFinishInfoList.add(teachingSuperviseFinishInfo3);

        //将数据集合转换成Javafx组件集合
        ObservableList<TeachingSuperviseFinishInfo>teachingSuperviseFinishInfos = FXCollections.observableArrayList(teachingSuperviseFinishInfoList);
        tableView.setItems(teachingSuperviseFinishInfos);

        //映射到表中
        serialNumColumn.setCellValueFactory(new PropertyValueFactory<TeachingSuperviseProcessInfo,String>("serialNum"));
        courseNameColumn.setCellValueFactory(new PropertyValueFactory<TeachingSuperviseProcessInfo,String>("courseName"));
        courseCharacterColumn.setCellValueFactory(new PropertyValueFactory<TeachingSuperviseProcessInfo,String>("character"));
        coursePropColumn.setCellValueFactory(new PropertyValueFactory<TeachingSuperviseProcessInfo,String>("courseProp"));
        courseTeacherColumn.setCellValueFactory(new PropertyValueFactory<TeachingSuperviseProcessInfo,String>("courseTeacher"));
        startCourseTimeColumn.setCellValueFactory(new PropertyValueFactory<TeachingSuperviseProcessInfo,String>("startTime"));
        finishCourseTimeColumn.setCellValueFactory(new PropertyValueFactory<TeachingSuperviseProcessInfo,String>("finishTime"));
        operationColumn.setCellValueFactory(new PropertyValueFactory<TeachingSuperviseProcessInfo,String>("operation"));


        tableView.getColumns().addAll(serialNumColumn,courseNameColumn,courseCharacterColumn,coursePropColumn,courseTeacherColumn,startCourseTimeColumn,finishCourseTimeColumn,operationColumn);

        tableVBox.getChildren().add(tableView);



    }

    /**
     * 条件搜索区域盒子
     * @param searchHBox
     */
    private void initSearchHBox(HBox searchHBox) {
        //搜索区域横向盒子间距
        searchHBox.setSpacing(15);
        searchHBox.setPadding(new Insets(10));
        //课程开设单位下拉框
        ComboBox courseUnitCB = new ComboBox<>();
        courseUnitCB.getItems().add("课程开设单位");
        courseUnitCB.getItems().add("全部");
        courseUnitCB.getItems().add("北京师范大学");
        courseUnitCB.getItems().add("东北师范大学");
        courseUnitCB.getItems().add("西南大学");
        courseUnitCB.getSelectionModel().selectFirst();
        //适用层次下拉框
        ComboBox levelCB = new ComboBox<>();
        levelCB.getItems().add("适用层次");
        levelCB.getItems().add("全部");
        levelCB.getItems().add("免费师范生");
        levelCB.getItems().add("免费师范生教育硕士");
        levelCB.getItems().add("职后教育");
        levelCB.getItems().add("其他");
        levelCB.getSelectionModel().selectFirst();
        //课程性质下拉框
        ComboBox courseCharacterCB = new ComboBox<>();
        courseCharacterCB.getItems().add("课程性质");
        courseCharacterCB.getItems().add("全部");
        courseCharacterCB.getItems().add("公共基础课");
        courseCharacterCB.getItems().add("专业基础课");
        courseCharacterCB.getItems().add("学位专业课");
        courseCharacterCB.getItems().add("教育实践");
        courseCharacterCB.getItems().add("其他");
        courseCharacterCB.getSelectionModel().selectFirst();
        //课程属性下拉框
        ComboBox coursePropCB = new ComboBox<>();
        coursePropCB.getItems().add("课程属性");
        coursePropCB.getItems().add("全部");
        coursePropCB.getItems().add("必修");
        coursePropCB.getItems().add("选修");
        coursePropCB.getSelectionModel().selectFirst();
        //要查询的课程编号文本框
        TextField detailCourseTF = new TextField();
        detailCourseTF.setPromptText("输入要查询的课程编号/课程名称");
        //搜索按钮
        Button searchBtn = new Button("搜索");

        searchHBox.getChildren().addAll(courseUnitCB,levelCB,courseCharacterCB,coursePropCB,searchBtn);
    }

    /**
     * 按钮横向盒子
     * @param buttonHBox
     */
    private void initButtonHBox(HBox buttonHBox) {
        buttonHBox.setSpacing(20);
        buttonHBox.setPadding(new Insets(5));
        //实施中的教学安排按钮
        Button processBtn = new Button("实施中的教学安排");
        //实施中的教学安排按钮事件
        ProcessTeachingArrangeBtnAction processTeachingArrangeBtnAction = new ProcessTeachingArrangeBtnAction();
        processBtn.setOnAction(processTeachingArrangeBtnAction);
        //已完成的教学安排按钮
        Button finishBtn = new Button("已完成的教学安排");
        buttonHBox.getChildren().addAll(processBtn,finishBtn);
    }

    /**
     * 顶部横向盒子
     * @param topHBox
     */
    private void initTopHBox(HBox topHBox) {
        topHBox.setSpacing(20);
        topHBox.setPadding(new Insets(5));
        //顶部标签
        Label topLab = new Label("当前位置：🏠>教学管理>教学监督>已完成的教学安排");
        topLab.setFont(new Font(20));//设置字体大小
        ObservableList<Node> children = topHBox.getChildren();
        children.addAll(topLab);
    }


}
